package com.kb.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.car.util.ConnectionPool;
import com.car.util.Util;
import com.kb.bean.KBOfPCAuto;

public class KBDaoOfPCAuto {
	private Connection conn = ConnectionPool.getConnection("pcauto", "root", "zhouzhou100428", "192.168.1.168");
	private Connection co = ConnectionPool.getConnection("carvoice_core", "root", "zhouzhou100428", "192.168.1.168");

	// 得到口碑的ID
	public List<Integer> getKBID() {
		List<Integer> list = new ArrayList<>();
		Statement st = null;
		ResultSet rs = null;
		String sql = "SELECT pcauto_id FROM core_brand_pcauto";
		try {
			st = co.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				int kbid = rs.getInt("pcauto_id");
				list.add(kbid);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return list;
	}

	// 插入口碑
	public void insertKB(KBOfPCAuto kb) {
		PreparedStatement ps = null;
		String sql = "INSERT INTO pcauto_kb(kb_id,kb_sfjh,kb_sftj,kb_ppid,kb_cxid,kb_cxmc,kb_fbrq,kb_gmsj,kb_gmdd,kb_lcj,kb_pjyh,kb_xslc,kb_nr,kb_zhpf,kb_wg,kb_ns,kb_kj,kb_pz,kb_dl,kb_ck,kb_yh,kb_ss,kb_hfs,kb_djs,kb_yhid,kb_yhmc) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, kb.getKb_id());
			ps.setInt(2, kb.getKb_sfjh());
			ps.setInt(3, kb.getKb_sftj());
			ps.setInt(4, kb.getKb_ppid());
			ps.setInt(5, kb.getKb_cxid());
			ps.setString(6, kb.getKb_cxmc());
			ps.setDate(7, (Date) Util.getDate(kb.getKb_fbrq()));
			ps.setDate(8, (Date) Util.getDate(kb.getKb_gmsj()));
			ps.setString(9, kb.getKb_gmdd());
			ps.setDouble(10, kb.getKb_lcj());
			ps.setDouble(11, kb.getKb_pjyh());
			ps.setInt(12, kb.getkb_xslc());
			ps.setString(13, kb.getKb_nr());
			ps.setDouble(14, kb.getKb_zhpf());
			ps.setInt(15, kb.getKb_wg());
			ps.setInt(16, kb.getKb_ns());
			ps.setInt(17, kb.getKb_kj());
			ps.setInt(18, kb.getKb_pz());
			ps.setInt(19, kb.getKb_dl());
			ps.setInt(20, kb.getKb_ck());
			ps.setInt(21, kb.getKb_yh());
			ps.setInt(22, kb.getKb_ss());
			ps.setInt(23, kb.getKb_hfs());
			ps.setInt(24, kb.getKb_djs());
			ps.setInt(25, kb.getKb_yhid());
			ps.setString(26, kb.getKb_yhmc());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updateBBSTime(String type, int id) {
		PreparedStatement ps = null;
		String sql = "UPDATE core_brand_pcauto AS pc SET pc." + type + "=NOW() WHERE pc.pcauto_id=" + id;
		try {
			ps = co.prepareStatement(sql);
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
